<?php

require_once 'SmartL/Zend/Controller/Action.php';
require_once 'SmartL/Version.php';
require_once 'Demo/ValidationMessage.php';
require_once 'Zend/Mail.php';

class InfoController extends SmartL_Zend_Controller_Action {
	public function indexAction()
	{
		$this->view->languages = $this->application->getLanguages();
		
		$this->view->zendFrameworkVersion = SmartL_Version::getZendFrameworkVersion();
		$this->view->doctrineVersion = SmartL_Version::getDoctrineVersion();
		$this->view->smartLVersion = SmartL_Version::VERSION;
	}
	
	public function contactsAction()
	{		
        $form = SmartL_Zend_Form::getForm(
        	$this->config->getAction("contacts")->getForm("contact"), 
        	$this->translations['default']);
			
		if (isset($_POST['contactAction'])) {
			if ($form->isValid($_POST)) {
				$mail = new Zend_Mail();
				$mail->setBodyText($form->message->getValue());
				$mail->setFrom($form->email->getValue(), 'E-shop customer');
				$to = SmartL_Application::getInstance()->getConfig()->demo->contact->email->getValue();
				$mail->addTo($to, 'Admin');
				$mail->setSubject('E-shop query');
				$mail->send();
				$this->_helper->redirector->goto("contacts-ok", "info");
			}
		}
		
		Demo_ValidationMessage::register($this->view);	
		$this->view->form = $form;
	}
	
	public function contactsOkAction() {}
}